use std::fs::OpenOptions;
use crate::lincni::{
    cmd::{ Dispatcher},
    plugin::PluginInfo,
};
use runner::{Run};
use crate::client::tcp::Client;
use crate::lincni::cmd::CmdArgs;
use crate::lincni::types::ErrorResponse;
use crate::runner::Runner;
use crate::types::request::UnixRequest;

mod command;
mod lincni;
mod sys;
mod runner;
mod types;
mod client;

// fn main () {
//     let runner = Run::new();
//     let mut w = OpenOptions::new()
//         .read(true)
//         .write(true)
//         .create(true)
//         .open("/home/test.log")
//         .unwrap();
//
//     let arg = CmdArgs{
//         container_id: "5dcbff0445f1f48af32ad1e87c7b2d4dcb4e5c386b3f7a91bbc72d75af5357c9".to_string(),
//         net_ns: "/proc/22417/ns/net".to_string(),
//         if_name: "eth0".to_string(),
//         args: "IgnoreUnknown=1;K8S_POD_NAMESPACE=default;K8S_POD_NAME=busybox-78644c6f64-czkz8;K8S_POD_INFRA_CONTAINER_ID=5dcbff0445f1f48af32ad1e87c7b2d4dcb4e5c386b3f7a91bbc72d75af5357c9".to_string(),
//         path: "/opt/cni/bin".to_string(),
//         stdin_data: vec![123, 34, 98, 114, 105, 100, 103, 101, 34, 58, 34, 114, 115, 99, 110, 105, 48, 34, 44, 34, 99, 110, 105, 86, 101, 114, 115, 105, 111, 110, 34, 58, 34, 48, 46, 51, 46, 49, 34, 44, 34, 110, 97, 109, 101, 34, 58, 34, 99, 98, 114, 48, 34, 44, 34, 112, 114, 101, 118, 82, 101, 115, 117, 108, 116, 34, 58, 123, 34, 99, 110, 105, 86, 101, 114, 115, 105, 111, 110, 34, 58, 34, 48, 46, 51, 46, 49, 34, 44, 34, 105, 110, 116, 101, 114, 102, 97, 99, 101, 115, 34, 58, 91, 123, 34, 110, 97, 109, 101, 34, 58, 34, 99, 110, 105, 48, 34, 44, 34, 109, 97, 99, 34, 58, 34, 51, 50, 58, 49, 100, 58, 100, 48, 58, 98, 52, 58, 102, 97, 58, 53, 102, 34, 125, 44, 123, 34, 110, 97, 109, 101, 34, 58, 34, 118, 101, 116, 104, 100, 98, 56, 97, 53, 52, 50, 98, 34, 44, 34, 109, 97, 99, 34, 58, 34, 54, 54, 58, 55, 52, 58, 98, 98, 58, 54, 102, 58, 100, 54, 58, 102, 56, 34, 125, 44, 123, 34, 110, 97, 109, 101, 34, 58, 34, 101, 116, 104, 48, 34, 44, 34, 109, 97, 99, 34, 58, 34, 56, 50, 58, 48, 99, 58, 102, 54, 58, 55, 97, 58, 57, 55, 58, 51, 57, 34, 44, 34, 115, 97, 110, 100, 98, 111, 120, 34, 58, 34, 47, 112, 114, 111, 99, 47, 50, 50, 52, 49, 55, 47, 110, 115, 47, 110, 101, 116, 34, 125, 93, 44, 34, 105, 112, 115, 34, 58, 91, 123, 34, 118, 101, 114, 115, 105, 111, 110, 34, 58, 34, 52, 34, 44, 34, 105, 110, 116, 101, 114, 102, 97, 99, 101, 34, 58, 50, 44, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 34, 49, 48, 46, 49, 50, 50, 46, 49, 46, 55, 56, 47, 50, 52, 34, 44, 34, 103, 97, 116, 101, 119, 97, 121, 34, 58, 34, 49, 48, 46, 49, 50, 50, 46, 49, 46, 49, 34, 125, 93, 44, 34, 114, 111, 117, 116, 101, 115, 34, 58, 91, 123, 34, 100, 115, 116, 34, 58, 34, 49, 48, 46, 49, 50, 50, 46, 48, 46, 48, 47, 49, 54, 34, 125, 44, 123, 34, 100, 115, 116, 34, 58, 34, 48, 46, 48, 46, 48, 46, 48, 47, 48, 34, 44, 34, 103, 119, 34, 58, 34, 49, 48, 46, 49, 50, 50, 46, 49, 46, 49, 34, 125, 93, 44, 34, 100, 110, 115, 34, 58, 123, 125, 125, 44, 34, 115, 117, 98, 110, 101, 116, 34, 58, 34, 49, 48, 46, 48, 46, 48, 46, 49, 34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 114, 115, 99, 110, 105, 34, 125]
//     };
//     match runner.add(&arg, &mut w) {
//         Ok(_) => {println!("{}","ok")}
//         Err(e) => {println!("err:{}",e.details)}
//     }
// }

fn main() {
    let mut d = Dispatcher::new_from_env();
    let runner = Run::new();

    match d.plugin_main_with_err(runner, PluginInfo::all(), "") {
        Ok(_) => {

        },
        Err(_) => {
            let r = r#"{
                "cniVersion": "0.3.1"
            }"#;
            println!("{}",r);
        }
    }
}

